<template>
	<teleport to="body">
		<div class="modal" v-if="visible">
			<div class="modal__overlay" @click="close"></div>
			<div class="modal__content">
				<slot></slot>
				<button @click="close">Close</button>
			</div>
		</div>
	</teleport>
</template>

<script>
	export default {
		props: {
			visible: {
				type: Boolean,
				required: true
			}
		},
		methods: {
			close() {
				this.$emit('update:visible', false)
			}
		}
	}
</script>

<style scoped>
	.modal {
		position: fixed;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		display: flex;
		justify-content: center;
		align-items: center;
		z-index: 9999;
	}

	.modal__overlay {
		position: fixed;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		background-color: rgba(0, 0, 0, 0.5);
	}

	.modal__content {
		background-color: #fff;
		padding: 20px;
	}
</style>